<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="烟团因子指数1" prop="PMXPFAC1001Num">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addPMXPFAC1001Num"
										v-model.number="ruleForm.PMXPFAC1001Num"
										:disabled=" this.senstivity_Data.PMXPFAC2001Num>0 || this.senstivity_Data.PRSCLCRW001Num>0 || this.senstivity_Data.PRSCLADP001Num>0 || this.senstivity_Data.PRSCLEFP001Num>0"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>

								<el-tabs :style="{'margin-left':'154px'}" class="m-20" v-model="activeName" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.PMXPFAC1001List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'PMXPFAC1001List.'+index+'.PMXPFAC1001' "
											:rules="rules.PMXPFAC1001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.PMXPFAC1001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>

								<el-form-item label="烟团因子指数2" prop="PMXPFAC2001Num">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addPMXPFAC2001Num"
										v-model.number="ruleForm.PMXPFAC2001Num"
										:disabled="this.senstivity_Data.PMXPFAC1001Num>0  || this.senstivity_Data.PRSCLCRW001Num>0 || this.senstivity_Data.PRSCLADP001Num>0 || this.senstivity_Data.PRSCLEFP001Num>0"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs :style="{'margin-left':'154px'}" class="m-20" v-model="activeName2" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.PMXPFAC2001List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'PMXPFAC2001List.'+index+'.PMXPFAC2001' "
											:rules="rules.PMXPFAC2001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.PMXPFAC2001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>
								<el-form-item label="烟云抬升模块临界 风速的线性因子" prop="PRSCLCRW001Num">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addPRSCLCRW001Num"
										v-model.number="ruleForm.PRSCLCRW001Num"
										:disabled="this.senstivity_Data.PMXPFAC1001Num>0 || this.senstivity_Data.PMXPFAC2001Num>0  || this.senstivity_Data.PRSCLADP001Num>0 || this.senstivity_Data.PRSCLEFP001Num>0"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs :style="{'margin-left':'154px'}" class="m-20" v-model="activeName3" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.PRSCLCRW001List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'PRSCLCRW001List.'+index+'.PRSCLCRW001' "
											:rules="rules.PRSCLCRW001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.PRSCLCRW001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>
								<el-form-item label="A到D稳定度线 性因子" prop="PRSCLADP001Num">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addPRSCLADP001Num"
										v-model.number="ruleForm.PRSCLADP001Num"
										:disabled="this.senstivity_Data.PMXPFAC1001Num>0 || this.senstivity_Data.PMXPFAC2001Num>0 || this.senstivity_Data.PRSCLCRW001Num>0  || this.senstivity_Data.PRSCLEFP001Num>0"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs :style="{'margin-left':'154px'}" class="m-20" v-model="activeName4" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.PRSCLADP001List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'PRSCLADP001List.'+index+'.PRSCLADP001' "
											:rules="rules.PRSCLADP001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.PRSCLADP001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>
								<el-form-item label="E到F稳定度线 性因子" prop="PRSCLEFP001Num">
									<el-input
										size="medium"
										class="mediumForm"
										@input="addPRSCLEFP001Num"
										v-model.number="ruleForm.PRSCLEFP001Num"
										:disabled="this.senstivity_Data.PMXPFAC1001Num>0 || this.senstivity_Data.PMXPFAC2001Num>0 || this.senstivity_Data.PRSCLCRW001Num>0 || this.senstivity_Data.PRSCLADP001Num>0 "
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs :style="{'margin-left':'154px'}" class="m-20" v-model="activeName5" type="card">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.PRSCLEFP001List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'PRSCLEFP001List.'+index+'.PRSCLEFP001' "
											:rules="rules.PRSCLEFP001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.PRSCLEFP001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.senstivity_Data.PMXPFAC1001Num>0 || this.senstivity_Data.PMXPFAC2001Num>0 || this.senstivity_Data.PRSCLCRW001Num>0 || this.senstivity_Data.PRSCLADP001Num>0 || this.senstivity_Data.PRSCLEFP001Num>0"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
					<el-button
						type="primary"
						v-if="this.senstivity_Data.PMXPFAC1001Num>0 || this.senstivity_Data.PMXPFAC2001Num>0 || this.senstivity_Data.PRSCLCRW001Num>0 || this.senstivity_Data.PRSCLADP001Num>0 || this.senstivity_Data.PRSCLEFP001Num>0"
						:loading="loading"
						@click="tijiao"
					>提 交</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import Axios from "axios"
import { dome, selecttext } from "@/utils/verify.js"

export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		var CHEVACST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.0) {
				callback(new Error("输入范围为[0.0，1000.0]"))
			} else {
				callback()
			}
		}
		var CHRELCST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.1) {
				callback(new Error("输入范围为[0.0，1000.1]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "5",
			activeName: "1",
			activeName2: "1",
			activeName3: "1",
			activeName4: "1",
			activeName5: "1",
			ruleForm: {
				PMXPFAC1001Num: "0",
				PMXPFAC1001List: [],
				PMXPFAC2001Num: "0",
				PMXPFAC2001List: [],
				PRSCLCRW001Num: "0",
				PRSCLCRW001List: [],
				PRSCLADP001Num: "0",
				PRSCLADP001List: [],
				PRSCLEFP001Num: "0",
				PRSCLEFP001List: [],

				PMXPFAC1001: 0.2,
				PMXPFAC2001: 0.25,
				PRSCLCRW001: 1,
				PRSCLADP001: 1,
				PRSCLEFP001: 1,
			},
			rules: {
				PMXPFAC1001: [
					{
						validator: dome(0.01, 1.0),
						trigger: ["change", "blur"],
					},
				],
				PMXPFAC2001: [
					{
						validator: dome(0.01, 1.0),
						trigger: ["change", "blur"],
					},
				],
				PRSCLCRW001: [
					{
						validator: dome(0.001, 1.0e6),
						trigger: ["change", "blur"],
					},
				],
				PRSCLADP001: [
					{
						validator: dome(0.01, 100),
						trigger: ["change", "blur"],
					},
				],
				PRSCLEFP001: [
					{
						validator: dome(0.01, 100.1),
						trigger: ["change", "blur"],
					},
				],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			senstivity_Data: (state) => state.token.senstivity_Data,
		}),
	},
	created() {
		// this.queryDetail()
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData() {
			this.ruleForm.PMXPFAC1001Num = this.senstivity_Data.PMXPFAC1001.length
			// console.log(this.ruleForm.PMXPFAC1001Num)
			this.addPMXPFAC1001Num(this.ruleForm.PMXPFAC1001Num)

			this.ruleForm.PMXPFAC2001Num = this.senstivity_Data.PMXPFAC2001.length
			// console.log(this.ruleForm.PMXPFAC2001Num)
			this.addPMXPFAC2001Num(this.ruleForm.PMXPFAC2001Num)

			this.ruleForm.PRSCLCRW001Num = this.senstivity_Data.PRSCLCRW001.length
			// console.log(this.ruleForm.PRSCLCRW001Num)
			this.addPRSCLCRW001Num(this.ruleForm.PRSCLCRW001Num)

			this.ruleForm.PRSCLADP001Num = this.senstivity_Data.PRSCLADP001.length
			// console.log(this.ruleForm.PRSCLADP001Num)
			this.addPRSCLADP001Num(this.ruleForm.PRSCLADP001Num)

			this.ruleForm.PRSCLEFP001Num = this.senstivity_Data.PRSCLEFP001.length
			// console.log(this.ruleForm.PRSCLEFP001Num)
			this.addPRSCLEFP001Num(this.ruleForm.PRSCLEFP001Num)
		},
		queryDetail() {
			// 查询明细
		},
		addPMXPFAC1001Num(value) {
			// console.log(value)
			this.ruleForm.PMXPFAC1001List = []
			for (let index = 1; index <= parseInt(value); index++) {
				this.ruleForm.PMXPFAC1001List.push({
					index: index.toString(),
					PMXPFAC1001: this.senstivity_Data.PMXPFAC1001[index - 1]
						? this.senstivity_Data.PMXPFAC1001[index - 1]
						: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.PMXPFAC1001Num = this.ruleForm.PMXPFAC1001Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		addPMXPFAC2001Num(value) {
			this.ruleForm.PMXPFAC2001List = []
			for (let index = 1; index <= parseInt(value); index++) {
				this.ruleForm.PMXPFAC2001List.push({
					index: index.toString(),
					PMXPFAC2001: this.senstivity_Data.PMXPFAC2001[index - 1]
						? this.senstivity_Data.PMXPFAC2001[index - 1]
						: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.PMXPFAC2001Num = this.ruleForm.PMXPFAC2001Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		addPRSCLCRW001Num(value) {
			this.ruleForm.PRSCLCRW001List = []
			for (let index = 1; index <= parseInt(value); index++) {
				this.ruleForm.PRSCLCRW001List.push({
					index: index.toString(),
					PRSCLCRW001: this.senstivity_Data.PRSCLCRW001[index - 1]
						? this.senstivity_Data.PRSCLCRW001[index - 1]
						: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.PRSCLCRW001Num = this.ruleForm.PRSCLCRW001Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		addPRSCLADP001Num(value) {
			this.ruleForm.PRSCLADP001List = []
			for (let index = 1; index <= parseInt(value); index++) {
				this.ruleForm.PRSCLADP001List.push({
					index: index.toString(),
					PRSCLADP001: this.senstivity_Data.PRSCLADP001[index - 1]
						? this.senstivity_Data.PRSCLADP001[index - 1]
						: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.PRSCLADP001Num = this.ruleForm.PRSCLADP001Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		addPRSCLEFP001Num(value) {
			this.ruleForm.PRSCLEFP001List = []
			for (let index = 1; index <= parseInt(value); index++) {
				this.ruleForm.PRSCLEFP001List.push({
					index: index.toString(),
					PRSCLEFP001: this.senstivity_Data.PRSCLEFP001[index - 1]
						? this.senstivity_Data.PRSCLEFP001[index - 1]
						: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.PRSCLEFP001Num = this.ruleForm.PRSCLEFP001Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
		},
		tijiao() {
			this.$refs.form.validate((valid) => {
				if (valid) {
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					)

					if (this.ruleForm.PMXPFAC1001Num > 0) {
						let tempPMXPFAC1001 = this.ruleForm.PMXPFAC1001List.map(
							(item) => {
								return parseFloat(item.PMXPFAC1001)
							}
						)
						tempdata.PMXPFAC1001 = tempPMXPFAC1001
					} else {
						tempdata.PMXPFAC1001 = []
					}

					if (this.ruleForm.PMXPFAC2001Num > 0) {
						tempdata.PMXPFAC2001 = this.ruleForm.PMXPFAC2001List.map(
							(item) => {
								return parseFloat(item.PMXPFAC2001)
							}
						)
					} else {
						tempdata.PMXPFAC2001 = []
					}

					if (this.ruleForm.PRSCLCRW001Num > 0) {
						tempdata.PRSCLCRW001 = this.ruleForm.PRSCLCRW001List.map(
							(item) => {
								return parseFloat(item.PRSCLCRW001)
							}
						)
					} else {
						tempdata.PRSCLCRW001 = []
					}

					if (this.ruleForm.PRSCLADP001Num > 0) {
						tempdata.PRSCLADP001 = this.ruleForm.PRSCLADP001List.map(
							(item) => {
								return parseFloat(item.PRSCLADP001)
							}
						)
					} else {
						tempdata.PRSCLADP001 = []
					}

					if (this.ruleForm.PRSCLEFP001Num > 0) {
						tempdata.PRSCLEFP001 = this.ruleForm.PRSCLEFP001List.map(
							(item) => {
								return parseFloat(item.PRSCLEFP001)
							}
						)
					} else {
						tempdata.PRSCLEFP001 = []
					}
					tempdata.SETPAGEINDEX = this.activeTab
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					}
					// console.log(params)
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
								this.$router.go(-1)
							}
						})
						.catch((err) => {
							console.log(err)
						})
				}
			})
		},
		submitFun() {
			this.$refs.form.validate((valid) => {
				if (valid) {
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					)
					if (this.ruleForm.PMXPFAC1001Num > 0) {
						let tempPMXPFAC1001 = this.ruleForm.PMXPFAC1001List.map(
							(item) => {
								return parseFloat(item.PMXPFAC1001)
							}
						)
						tempdata.PMXPFAC1001 = tempPMXPFAC1001
					} else {
						tempdata.PMXPFAC1001 = []
					}

					if (this.ruleForm.PMXPFAC2001Num > 0) {
						tempdata.PMXPFAC2001 = this.ruleForm.PMXPFAC2001List.map(
							(item) => {
								return parseFloat(item.PMXPFAC2001)
							}
						)
					} else {
						tempdata.PMXPFAC2001 = []
					}
					if (this.ruleForm.PRSCLCRW001Num > 0) {
						tempdata.PRSCLCRW001 = this.ruleForm.PRSCLCRW001List.map(
							(item) => {
								return parseFloat(item.PRSCLCRW001)
							}
						)
					} else {
						tempdata.PRSCLCRW001 = []
					}
					if (this.ruleForm.PRSCLADP001Num > 0) {
						tempdata.PRSCLADP001 = this.ruleForm.PRSCLADP001List.map(
							(item) => {
								return parseFloat(item.PRSCLADP001)
							}
						)
					} else {
						tempdata.PRSCLADP001 = []
					}
					if (this.ruleForm.PRSCLEFP001Num > 0) {
						tempdata.PRSCLEFP001 = this.ruleForm.PRSCLEFP001List.map(
							(item) => {
								return parseFloat(item.PRSCLEFP001)
							}
						)
					} else {
						tempdata.PRSCLEFP001 = []
					}
					// tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_senstivity_Data", tempdata)
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					}
					// console.log(params)
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							// console.log(res)
							var str = res.data.substring(0, 1)
							var message = res.data.substring(6)
							if (str == "E") {
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_senstivity_showTab",
						this.activeTab
					)
				}
			})
		},
		daochu() {
			//导出
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>